package com.hwl.lab.service;

import com.hwl.lab.entity.User;
import com.hwl.lab.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;
    //分页实现
    public Page<User> findAll( Integer page, Integer size){
        Pageable pageable=  PageRequest.of(page-1,size);
        return userRepository.findAll(pageable);
    }
    //通过账号查询
    public User findByUseridA(String userid){
        return userRepository.findByUserid(userid);
    }
    //保存，修改
    public User saveUser(User user){
       return  userRepository.save(user);
    }
    //通过账号删除
    public void deleteByUserid(String userid){
        userRepository.deleteByUserid(userid);
    }

}
